package br.com.caelum.vraptor.controller;

import java.util.List;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.componentes.ProfessorWeb;
import br.com.caelum.vraptor.dao.ProfessorDAO;
import br.com.caelum.vraptor.entidades.Professor;

@Controller
public class ProfessorController {
	
	@Inject
	private Result result;
	
	@Inject
	private ProfessorDAO dao;
	
	@Inject
	private ProfessorWeb professorWeb;

	public void add(){
		
	}
	
	
	public List<Professor> list(){
		return dao.find();
		
	}
	public void login(){
		
	}
	public void logar(String email, String senha){
		Professor n = dao.find(email, senha);
		if(n==null){result.redirectTo(ProfessorController.class).login();}
		professorWeb.login(n);
		result.redirectTo(IndexController.class).index();
		
	}
	
	public void save(Professor professor){
		
		dao.save(professor);
		
		result.redirectTo(ProfessorController.class).login();
	}
	
	public Professor edit(Integer id){
		return dao.find(id);
	}
	
	public void delete(int id){
		Professor professor = new Professor();
		professor.setId(id);
		dao.delete(professor);
		result.redirectTo(ProfessorController.class).list();
	}
	
}
